package com.tianji.api.client.promotion.fallback;

import com.tianji.api.client.promotion.PromotionClient;
import com.tianji.api.dto.promotion.CouponDiscountDTO;
import com.tianji.api.dto.promotion.OrderCourseDTO;
import com.tianji.common.exceptions.BizIllegalException;
import com.tianji.common.utils.CollUtils;
import com.tianji.promotion.domain.dto.OrderCouponDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;

import java.util.List;

@Slf4j
public class PromotionClientFallback implements FallbackFactory<PromotionClient> {
    @Override
    public PromotionClient create(Throwable cause) {
      log.error("查询优惠券服务异常",cause);
      return new PromotionClient() {
          @Override
          public List<CouponDiscountDTO> findDiscountSolution(List<OrderCourseDTO> orderCourses) {
              return CollUtils.emptyList();
          }

          @Override
          public CouponDiscountDTO queryDiscountDetailByOrder(OrderCouponDTO orderCouponDTO) {
              return null;
          }

          @Override
          public void writeOffCoupon(List<Long> userCouponIds) {
              throw new BizIllegalException(500,"核销优惠券异常",cause);
          }

          @Override
          public void refundCoupon(List<Long> userCouponIds) {
              throw new BizIllegalException(500,"退还优惠券异常",cause);
          }

          @Override
          public List<String> queryDiscountRules(List<Long> userCouponIds) {
              return CollUtils.emptyList();
          }
      };
    }
}
